Skip to content

feat: script builder#163

Open
ascandone wants to merge 8 commits into
mainfrom
feat/script-builder
Open

feat: script builder#163
ascandone wants to merge 8 commits into
mainfrom
feat/script-builder

Conversation

@ascandone

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ascandone, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 13 minutes and 37 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f03fc240-3ddf-4326-bdaa-08767ee9b3e1

📥 Commits

Reviewing files that changed from the base of the PR and between 126e9a1 and 4eb046c.

📒 Files selected for processing (2)
  • builder/builder_test.go
  • builder/vars.go

Walkthrough

A new builder package is introduced that provides a typed Go DSL for constructing numscript programs. It includes a generic pool-based ID system, expression type interfaces, variable management with Var[T] and VarsEnv, source/destination/statement renderers, automatic vars { } block generation, and a BuildProgram entry point. Five test cases validate the generated output.

Changes

Numscript program builder DSL

Layer / File(s) Summary
Core infrastructure: ExprType interfaces, pool, env, render type, and name helpers
builder/expression_type.go, builder/pool.go, builder/builder.go
Defines exported ExprType marker interfaces and five typed sub-interfaces, a generic pool[T] for stable ID assignment, the env struct holding four typed pools and a shared strings.Builder, and ID-to-name helpers (accountToName, assetToName, stringToName, numberToName).
Variable system: Var, constructors, VarsEnv, and Fill methods
builder/vars.go
Introduces generic Var[T ExprType] with a lazy alloc closure, VarsEnv with a type-erased bindings map, four New*Var constructors each bound to a specific pool, and Fill* methods returning (varName, valueString) pairs including big-integer string conversion.
Expression constructors
builder/expression.go
Exports Expression[T] as a render alias, then ExprVar (with bindings-cache), ExprAccount/ExprAsset/ExprString (pool-routed), ExprNumberBigInt (direct write), and ExprMonetary (bracketed composition of asset and amount).
Statement DSL: Source, Destination, Statement
builder/source.go, builder/destination.go, builder/statement.go
Defines Source, Destination, and Statement as render-function aliases; adds SrcAccount, SrcColored, SrcInorder, DestAccount, and StmtSend constructors for building indented send blocks with sources and destinations.
Vars block rendering and BuildProgram entry point
builder/builder.go
Implements varRenderState, renderVar, and renderVars to emit the vars { ... } block from referenced pool IDs and populate knownBindings; BuildProgram orchestrates env creation, statement rendering, and returns (knownBindings, varsEnv, vars+body).
Tests
builder/builder_test.go
Five test functions covering simple send, inorder multi-account, nested inorder, inorder with colored accounts, and external variable injection via Fill*; each asserts the inline snapshot script and vars bindings map.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 A builder hops in, brand new today,
With pools and expressions to render away.
StmtSend leaps forth, SrcInorder lines up,
vars { } bloom neatly—just fill up the cup!
From ExprMonetary to BuildProgram's gleam,
The numscript now flows like a well-hopped stream. 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess relevance to the changeset. Add a pull request description explaining the purpose, scope, and key components of the script builder package introduced in this change.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: script builder' clearly summarizes the main purpose of the changeset, which introduces a comprehensive builder package for constructing formatted numscript programs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/script-builder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.52381% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.31%. Comparing base (cbc11e8) to head (4eb046c).

Files with missing lines Patch % Lines
builder/vars.go 48.64% 19 Missing ⚠️
builder/builder.go 89.55% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #163      +/-   ##
==========================================
+ Coverage   67.81%   68.31%   +0.50%     
==========================================
  Files          49       56       +7     
  Lines        5223     5391     +168     
==========================================
+ Hits         3542     3683     +141     
- Misses       1472     1495      +23     
- Partials      209      213       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Changes requested — automated review

The new builder can emit invalid scripts when builder values are reused, and its typed variable API does not enforce the advertised variable type at compile time. These are correctness issues in the newly introduced public API.

Comment thread builder/expression.go Outdated
Comment thread builder/vars.go Outdated
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approve — automated review

No discrete correctness issues were identified in the introduced builder implementation based on the diff and repository context.

No findings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@builder/vars.go`:
- Around line 57-59: The FillAccount method and similar methods (at lines 62-64,
67-69, 72-74) silently ignore failed variable lookups by discarding the success
boolean returned from the map access operation using a blank identifier. Instead
of ignoring the second return value from v.bindings lookups, capture it and
validate that the variable binding exists, returning an error or failing fast if
the variable is not found in the bindings map. Apply this validation pattern to
all affected methods to ensure missing variable bindings are caught immediately
rather than propagating invalid empty string names downstream.
- Around line 72-74: The FillNumber function does not check if the bi parameter
is nil before calling bi.String() on line 74, which will cause a panic if bi is
nil. Add an explicit nil check for the bi parameter before calling bi.String(),
and return an appropriate string representation (such as empty string or "nil")
when bi is nil to prevent the panic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd1c5ee4-c3ef-4a1e-8998-0fd9a9e65bf0

📥 Commits

Reviewing files that changed from the base of the PR and between 39ba793 and ba27dbe.

📒 Files selected for processing (4)
  • builder/builder.go
  • builder/builder_test.go
  • builder/expression.go
  • builder/vars.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • builder/expression.go
  • builder/builder_test.go

Comment thread builder/vars.go
Comment on lines +57 to +59
func (v VarsEnv) FillAccount(var_ *Var[ExprTypeAccount], account string) (string, string) {
name, _ := v.bindings[anyVar(var_)]
return name, account

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail fast when a variable is not bound in VarsEnv.

At Line 58/63/68/73, missing keys are silently converted into "" names. That can emit invalid bindings downstream without any explicit failure signal. Validate lookup success and fail fast.

Suggested fix
 func (v VarsEnv) FillAccount(var_ *Var[ExprTypeAccount], account string) (string, string) {
-	name, _ := v.bindings[anyVar(var_)]
+	name, ok := v.bindings[anyVar(var_)]
+	if !ok {
+		panic("FillAccount called with variable not allocated in program")
+	}
 	return name, account
 }

 func (v VarsEnv) FillAsset(var_ *Var[ExprTypeAsset], asset string) (string, string) {
-	name, _ := v.bindings[anyVar(var_)]
+	name, ok := v.bindings[anyVar(var_)]
+	if !ok {
+		panic("FillAsset called with variable not allocated in program")
+	}
 	return name, asset
 }

 func (v VarsEnv) FillString(var_ *Var[ExprTypeString], str string) (string, string) {
-	name, _ := v.bindings[anyVar(var_)]
+	name, ok := v.bindings[anyVar(var_)]
+	if !ok {
+		panic("FillString called with variable not allocated in program")
+	}
 	return name, str
 }

 func (v VarsEnv) FillNumber(var_ *Var[ExprTypeNumber], bi *big.Int) (string, string) {
-	name, _ := v.bindings[anyVar(var_)]
+	name, ok := v.bindings[anyVar(var_)]
+	if !ok {
+		panic("FillNumber called with variable not allocated in program")
+	}
 	return name, bi.String()
 }

Also applies to: 62-64, 67-69, 72-74

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@builder/vars.go` around lines 57 - 59, The FillAccount method and similar
methods (at lines 62-64, 67-69, 72-74) silently ignore failed variable lookups
by discarding the success boolean returned from the map access operation using a
blank identifier. Instead of ignoring the second return value from v.bindings
lookups, capture it and validate that the variable binding exists, returning an
error or failing fast if the variable is not found in the bindings map. Apply
this validation pattern to all affected methods to ensure missing variable
bindings are caught immediately rather than propagating invalid empty string
names downstream.

Comment thread builder/vars.go
Comment on lines +72 to +74
func (v VarsEnv) FillNumber(var_ *Var[ExprTypeNumber], bi *big.Int) (string, string) {
name, _ := v.bindings[anyVar(var_)]
return name, bi.String()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard FillNumber against nil *big.Int.

At Line 74, bi.String() will panic when bi == nil. Add an explicit nil check before conversion.

Suggested fix
 func (v VarsEnv) FillNumber(var_ *Var[ExprTypeNumber], bi *big.Int) (string, string) {
 	name, _ := v.bindings[anyVar(var_)]
+	if bi == nil {
+		panic("FillNumber called with nil *big.Int")
+	}
 	return name, bi.String()
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (v VarsEnv) FillNumber(var_ *Var[ExprTypeNumber], bi *big.Int) (string, string) {
name, _ := v.bindings[anyVar(var_)]
return name, bi.String()
func (v VarsEnv) FillNumber(var_ *Var[ExprTypeNumber], bi *big.Int) (string, string) {
name, _ := v.bindings[anyVar(var_)]
if bi == nil {
panic("FillNumber called with nil *big.Int")
}
return name, bi.String()
}
🧰 Tools
🪛 GitHub Actions: Default / Dirty

[error] 55-74: CI failed because the repository had uncommitted changes. The step 'git status --porcelain' detected modifications and exited with code 1 after showing 'There are changes in the repository' and running 'git diff' for modified file 'builder/vars.go'. Diff indicates changes to variable binding assignments in FillAccount/FillAsset/FillString/FillNumber.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@builder/vars.go` around lines 72 - 74, The FillNumber function does not check
if the bi parameter is nil before calling bi.String() on line 74, which will
cause a panic if bi is nil. Add an explicit nil check for the bi parameter
before calling bi.String(), and return an appropriate string representation
(such as empty string or "nil") when bi is nil to prevent the panic.

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approve — automated review

No discrete correctness issues were identified in the added builder package based on the diff and surrounding parser/runtime expectations.

No findings.

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approve — automated review

No discrete correctness issues were found in the added builder implementation based on the diff and existing Numscript grammar/API expectations.

No findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants